<%@page import="com.group1.bookmanagement.domain.User"%>
<%@page import="com.group1.bookmanagement.service.UserService"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@page contentType="text/html; charset=UTF-8" language="java"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String ctx = request.getContextPath();
	pageContext.setAttribute("ctx", ctx);

	if (session.getAttribute("user") == null) {
		//自动登录凭据
		String loginCredential = null;
		//查找本地cookie是否保存自动登录凭据
		Cookie[] cookies = request.getCookies();
		for (Cookie cookie : cookies) {
			if (cookie.getName().equals("loginCredential")) {
				loginCredential = cookie.getValue();
			}
		}

		if (loginCredential != null) {
			ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
			UserService userService = (UserService) context.getBean("userService");
			User user = userService.autoLogin(loginCredential);
			session.setAttribute("user", user);
		}
	}
%>